﻿using System;
using System.Collections;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using HslCommunication.BasicFramework;
using HslCommunication.Core;
using HslCommunication.Core.IMessage;
using HslCommunication.Core.Net;
using HslCommunication.Reflection;

namespace HslCommunication.Profinet.LSIS
{
	/// <summary>
	/// XGB Fast Enet I/F module supports open Ethernet. It provides network configuration that is to connect LSIS and other company PLC, PC on network
	/// </summary>
	/// <remarks>
	/// Address example likes the follow
	/// <list type="table">
	///   <listheader>
	///     <term>地址名称</term>
	///     <term>地址代号</term>
	///     <term>示例</term>
	///     <term>地址进制</term>
	///     <term>字操作</term>
	///     <term>位操作</term>
	///     <term>备注</term>
	///   </listheader>
	///   <item>
	///     <term>*</term>
	///     <term>P</term>
	///     <term>PX100,PB100,PW100,PD100,PL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>*</term>
	///     <term>M</term>
	///     <term>MX100,MB100,MW100,MD100,ML100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>*</term>
	///     <term>L</term>
	///     <term>LX100,LB100,LW100,LD100,LL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>*</term>
	///     <term>K</term>
	///     <term>KX100,KB100,KW100,KD100,KL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term>*</term>
	///     <term>F</term>
	///     <term>FX100,FB100,FW100,FD100,FL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>T</term>
	///     <term>TX100,TB100,TW100,TD100,TL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>C</term>
	///     <term>CX100,CB100,CW100,CD100,CL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>D</term>
	///     <term>DX100,DB100,DW100,DD100,DL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>S</term>
	///     <term>SX100,SB100,SW100,SD100,SL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>Q</term>
	///     <term>QX100,QB100,QW100,QD100,QL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>I</term>
	///     <term>IX100,IB100,IW100,ID100,IL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>N</term>
	///     <term>NX100,NB100,NW100,ND100,NL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>U</term>
	///     <term>UX100,UB100,UW100,UD100,UL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>Z</term>
	///     <term>ZX100,ZB100,ZW100,ZD100,ZL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	///   <item>
	///     <term></term>
	///     <term>R</term>
	///     <term>RX100,RB100,RW100,RD100,RL100</term>
	///     <term>10</term>
	///     <term>√</term>
	///     <term>√</term>
	///     <term></term>
	///   </item>
	/// </list>
	/// </remarks>
	// Token: 0x02000084 RID: 132
	public class XGBFastEnet : NetworkDeviceBase
	{
		/// <summary>
		/// Instantiate a Default object
		/// </summary>
		// Token: 0x06000A0B RID: 2571 RVA: 0x0003BC74 File Offset: 0x00039E74
		public XGBFastEnet()
		{
			base.WordLength = 2;
			this.IpAddress = "127.0.0.1";
			this.Port = 2004;
			base.ByteTransform = new RegularByteTransform();
		}

		/// <summary>
		/// Instantiate a object by ipaddress and port
		/// </summary>
		/// <param name="ipAddress">the ip address of the plc</param>
		/// <param name="port">the port of the plc, default is 2004</param>
		// Token: 0x06000A0C RID: 2572 RVA: 0x0003BCD8 File Offset: 0x00039ED8
		public XGBFastEnet(string ipAddress, int port)
		{
			base.WordLength = 2;
			this.IpAddress = ipAddress;
			this.Port = port;
			base.ByteTransform = new RegularByteTransform();
		}

		/// <summary>
		/// Instantiate a object by ipaddress, port, cpuType, slotNo
		/// </summary>
		/// <param name="CpuType">CpuType</param>
		/// <param name="ipAddress">the ip address of the plc</param>
		/// <param name="port">he port of the plc, default is 2004</param>
		/// <param name="slotNo">slot number</param>
		// Token: 0x06000A0D RID: 2573 RVA: 0x0003BD34 File Offset: 0x00039F34
		public XGBFastEnet(string CpuType, string ipAddress, int port, byte slotNo)
		{
			this.SetCpuType = CpuType;
			base.WordLength = 2;
			this.IpAddress = ipAddress;
			this.Port = port;
			this.slotNo = slotNo;
			base.ByteTransform = new RegularByteTransform();
		}

		/// <inheritdoc />
		// Token: 0x06000A0E RID: 2574 RVA: 0x0003BD9D File Offset: 0x00039F9D
		protected override INetMessage GetNewNetMessage()
		{
			return new LsisFastEnetMessage();
		}

		/// <summary>
		/// set plc
		/// </summary>
		// Token: 0x170001A5 RID: 421
		// (get) Token: 0x06000A0F RID: 2575 RVA: 0x0003BDA4 File Offset: 0x00039FA4
		// (set) Token: 0x06000A10 RID: 2576 RVA: 0x0003BDAC File Offset: 0x00039FAC
		public string SetCpuType { get; set; }

		/// <summary>
		/// CPU TYPE
		/// </summary>
		// Token: 0x170001A6 RID: 422
		// (get) Token: 0x06000A11 RID: 2577 RVA: 0x0003BDB5 File Offset: 0x00039FB5
		// (set) Token: 0x06000A12 RID: 2578 RVA: 0x0003BDBD File Offset: 0x00039FBD
		public string CpuType { get; private set; }

		/// <summary>
		/// Cpu is error
		/// </summary>
		// Token: 0x170001A7 RID: 423
		// (get) Token: 0x06000A13 RID: 2579 RVA: 0x0003BDC6 File Offset: 0x00039FC6
		// (set) Token: 0x06000A14 RID: 2580 RVA: 0x0003BDCE File Offset: 0x00039FCE
		public bool CpuError { get; private set; }

		/// <summary>
		/// RUN, STOP, ERROR, DEBUG
		/// </summary>
		// Token: 0x170001A8 RID: 424
		// (get) Token: 0x06000A15 RID: 2581 RVA: 0x0003BDD7 File Offset: 0x00039FD7
		// (set) Token: 0x06000A16 RID: 2582 RVA: 0x0003BDDF File Offset: 0x00039FDF
		public LSCpuStatus LSCpuStatus { get; private set; }

		/// <summary>
		/// FEnet I/F module’s Base No.
		/// </summary>
		// Token: 0x170001A9 RID: 425
		// (get) Token: 0x06000A17 RID: 2583 RVA: 0x0003BDE8 File Offset: 0x00039FE8
		// (set) Token: 0x06000A18 RID: 2584 RVA: 0x0003BDF0 File Offset: 0x00039FF0
		public byte BaseNo
		{
			get
			{
				return this.baseNo;
			}
			set
			{
				this.baseNo = value;
			}
		}

		/// <summary>
		/// FEnet I/F module’s Slot No.
		/// </summary>
		// Token: 0x170001AA RID: 426
		// (get) Token: 0x06000A19 RID: 2585 RVA: 0x0003BDF9 File Offset: 0x00039FF9
		// (set) Token: 0x06000A1A RID: 2586 RVA: 0x0003BE01 File Offset: 0x0003A001
		public byte SlotNo
		{
			get
			{
				return this.slotNo;
			}
			set
			{
				this.slotNo = value;
			}
		}

		/// <summary>
		///
		/// </summary>
		// Token: 0x170001AB RID: 427
		// (get) Token: 0x06000A1B RID: 2587 RVA: 0x0003BE0A File Offset: 0x0003A00A
		// (set) Token: 0x06000A1C RID: 2588 RVA: 0x0003BE12 File Offset: 0x0003A012
		public LSCpuInfo CpuInfo
		{
			get
			{
				return this.cpuInfo;
			}
			set
			{
				this.cpuInfo = value;
			}
		}

		/// <summary>
		///
		/// </summary>
		// Token: 0x170001AC RID: 428
		// (get) Token: 0x06000A1D RID: 2589 RVA: 0x0003BE1B File Offset: 0x0003A01B
		// (set) Token: 0x06000A1E RID: 2590 RVA: 0x0003BE23 File Offset: 0x0003A023
		public string CompanyID
		{
			get
			{
				return this.CompanyID1;
			}
			set
			{
				this.CompanyID1 = value;
			}
		}

		/// <inheritdoc />
		// Token: 0x06000A1F RID: 2591 RVA: 0x0003BE2C File Offset: 0x0003A02C
		[HslMqttApi("ReadByteArray", "")]
		public override OperateResult<byte[]> Read(string address, ushort length)
		{
			OperateResult<byte[]> operateResult = XGBFastEnet.BuildReadByteCommand(address, length);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(this.PackCommand(operateResult.Content));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<byte[]>(operateResult2);
				}
				else
				{
					result = this.ExtractActualData(operateResult2.Content);
				}
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x06000A20 RID: 2592 RVA: 0x0003BE90 File Offset: 0x0003A090
		[HslMqttApi("WriteByteArray", "")]
		public override OperateResult Write(string address, byte[] value)
		{
			OperateResult<byte[]> operateResult = this.BuildWriteByteCommand(address, value);
			bool flag = !operateResult.IsSuccess;
			OperateResult result;
			if (flag)
			{
				result = operateResult;
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(this.PackCommand(operateResult.Content));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<byte[]>(operateResult2);
				}
				else
				{
					result = this.ExtractActualData(operateResult2.Content);
				}
			}
			return result;
		}

		/// <inheritdoc />
		// Token: 0x06000A21 RID: 2593 RVA: 0x0003BEF4 File Offset: 0x0003A0F4
		[DebuggerStepThrough]
		public override Task<OperateResult<byte[]>> ReadAsync(string address, ushort length)
		{
			XGBFastEnet.<ReadAsync>d__34 <ReadAsync>d__ = new XGBFastEnet.<ReadAsync>d__34();
			<ReadAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte[]>>.Create();
			<ReadAsync>d__.<>4__this = this;
			<ReadAsync>d__.address = address;
			<ReadAsync>d__.length = length;
			<ReadAsync>d__.<>1__state = -1;
			<ReadAsync>d__.<>t__builder.Start<XGBFastEnet.<ReadAsync>d__34>(ref <ReadAsync>d__);
			return <ReadAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x06000A22 RID: 2594 RVA: 0x0003BF48 File Offset: 0x0003A148
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, byte[] value)
		{
			XGBFastEnet.<WriteAsync>d__35 <WriteAsync>d__ = new XGBFastEnet.<WriteAsync>d__35();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<XGBFastEnet.<WriteAsync>d__35>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc />
		// Token: 0x06000A23 RID: 2595 RVA: 0x0003BF9C File Offset: 0x0003A19C
		[HslMqttApi("ReadBoolArray", "")]
		public override OperateResult<bool[]> ReadBool(string address, ushort length)
		{
			OperateResult<byte[]> operateResult = XGBFastEnet.BuildReadByteCommand(address, length);
			bool flag = !operateResult.IsSuccess;
			OperateResult<bool[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<bool[]>(operateResult);
			}
			else
			{
				OperateResult<byte[]> operateResult2 = base.ReadFromCoreServer(this.PackCommand(operateResult.Content));
				bool flag2 = !operateResult2.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<bool[]>(operateResult2);
				}
				else
				{
					OperateResult<byte[]> operateResult3 = this.ExtractActualData(operateResult2.Content);
					bool flag3 = !operateResult3.IsSuccess;
					if (flag3)
					{
						result = OperateResult.CreateFailedResult<bool[]>(operateResult3);
					}
					else
					{
						result = OperateResult.CreateSuccessResult<bool[]>(SoftBasic.ByteToBoolArray(operateResult3.Content, (int)length));
					}
				}
			}
			return result;
		}

		/// <summary>
		/// ReadCoil
		/// </summary>
		/// <param name="address">Start address</param>
		/// <returns>Whether to read the successful</returns>
		// Token: 0x06000A24 RID: 2596 RVA: 0x0003AED6 File Offset: 0x000390D6
		public OperateResult<bool> ReadCoil(string address)
		{
			return this.ReadBool(address);
		}

		/// <summary>
		/// ReadCoil
		/// </summary>
		/// <param name="address">Start address</param>
		/// <param name="length">read address length</param>
		/// <returns>Whether to read the successful</returns>
		// Token: 0x06000A25 RID: 2597 RVA: 0x0003AEDF File Offset: 0x000390DF
		public OperateResult<bool[]> ReadCoil(string address, ushort length)
		{
			return this.ReadBool(address, length);
		}

		/// <summary>
		/// Read single byte value from plc
		/// </summary>
		/// <param name="address">Start address</param>
		/// <returns>Whether to write the successful</returns>
		// Token: 0x06000A26 RID: 2598 RVA: 0x0001BA1E File Offset: 0x00019C1E
		[HslMqttApi("ReadByte", "")]
		public OperateResult<byte> ReadByte(string address)
		{
			return ByteTransformHelper.GetResultFromArray<byte>(this.Read(address, 1));
		}

		/// <summary>
		/// Write single byte value to plc
		/// </summary>
		/// <param name="address">Start address</param>
		/// <param name="value">value</param>
		/// <returns>Whether to write the successful</returns>
		// Token: 0x06000A27 RID: 2599 RVA: 0x0001BA2D File Offset: 0x00019C2D
		[HslMqttApi("WriteByte", "")]
		public OperateResult Write(string address, byte value)
		{
			return this.Write(address, new byte[]
			{
				value
			});
		}

		/// <summary>
		/// WriteCoil
		/// </summary>
		/// <param name="address">Start address</param>
		/// <param name="value">bool value</param>
		/// <returns>Whether to write the successful</returns>
		// Token: 0x06000A28 RID: 2600 RVA: 0x0003C032 File Offset: 0x0003A232
		public OperateResult WriteCoil(string address, bool value)
		{
			byte[] array = new byte[2];
			array[0] = (value ? 1 : 0);
			return this.Write(address, array);
		}

		/// <summary>
		/// WriteCoil
		/// </summary>
		/// <param name="address">Start address</param>
		/// <param name="value">bool value</param>
		/// <returns>Whether to write the successful</returns>
		// Token: 0x06000A29 RID: 2601 RVA: 0x0003C04C File Offset: 0x0003A24C
		[HslMqttApi("WriteBool", "")]
		public override OperateResult Write(string address, bool value)
		{
			return this.WriteCoil(address, value);
		}

		/// <inheritdoc />
		// Token: 0x06000A2A RID: 2602 RVA: 0x0003C058 File Offset: 0x0003A258
		[DebuggerStepThrough]
		public override Task<OperateResult<bool[]>> ReadBoolAsync(string address, ushort length)
		{
			XGBFastEnet.<ReadBoolAsync>d__43 <ReadBoolAsync>d__ = new XGBFastEnet.<ReadBoolAsync>d__43();
			<ReadBoolAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadBoolAsync>d__.<>4__this = this;
			<ReadBoolAsync>d__.address = address;
			<ReadBoolAsync>d__.length = length;
			<ReadBoolAsync>d__.<>1__state = -1;
			<ReadBoolAsync>d__.<>t__builder.Start<XGBFastEnet.<ReadBoolAsync>d__43>(ref <ReadBoolAsync>d__);
			return <ReadBoolAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.LSIS.XGBFastEnet.ReadCoil(System.String)" />
		// Token: 0x06000A2B RID: 2603 RVA: 0x0003C0AC File Offset: 0x0003A2AC
		[DebuggerStepThrough]
		public Task<OperateResult<bool>> ReadCoilAsync(string address)
		{
			XGBFastEnet.<ReadCoilAsync>d__44 <ReadCoilAsync>d__ = new XGBFastEnet.<ReadCoilAsync>d__44();
			<ReadCoilAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool>>.Create();
			<ReadCoilAsync>d__.<>4__this = this;
			<ReadCoilAsync>d__.address = address;
			<ReadCoilAsync>d__.<>1__state = -1;
			<ReadCoilAsync>d__.<>t__builder.Start<XGBFastEnet.<ReadCoilAsync>d__44>(ref <ReadCoilAsync>d__);
			return <ReadCoilAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.LSIS.XGBFastEnet.ReadCoil(System.String,System.UInt16)" />
		// Token: 0x06000A2C RID: 2604 RVA: 0x0003C0F8 File Offset: 0x0003A2F8
		[DebuggerStepThrough]
		public Task<OperateResult<bool[]>> ReadCoilAsync(string address, ushort length)
		{
			XGBFastEnet.<ReadCoilAsync>d__45 <ReadCoilAsync>d__ = new XGBFastEnet.<ReadCoilAsync>d__45();
			<ReadCoilAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<bool[]>>.Create();
			<ReadCoilAsync>d__.<>4__this = this;
			<ReadCoilAsync>d__.address = address;
			<ReadCoilAsync>d__.length = length;
			<ReadCoilAsync>d__.<>1__state = -1;
			<ReadCoilAsync>d__.<>t__builder.Start<XGBFastEnet.<ReadCoilAsync>d__45>(ref <ReadCoilAsync>d__);
			return <ReadCoilAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.LSIS.XGBFastEnet.ReadByte(System.String)" />
		// Token: 0x06000A2D RID: 2605 RVA: 0x0003C14C File Offset: 0x0003A34C
		[DebuggerStepThrough]
		public Task<OperateResult<byte>> ReadByteAsync(string address)
		{
			XGBFastEnet.<ReadByteAsync>d__46 <ReadByteAsync>d__ = new XGBFastEnet.<ReadByteAsync>d__46();
			<ReadByteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult<byte>>.Create();
			<ReadByteAsync>d__.<>4__this = this;
			<ReadByteAsync>d__.address = address;
			<ReadByteAsync>d__.<>1__state = -1;
			<ReadByteAsync>d__.<>t__builder.Start<XGBFastEnet.<ReadByteAsync>d__46>(ref <ReadByteAsync>d__);
			return <ReadByteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.LSIS.XGBFastEnet.Write(System.String,System.Byte)" />
		// Token: 0x06000A2E RID: 2606 RVA: 0x0003C198 File Offset: 0x0003A398
		[DebuggerStepThrough]
		public Task<OperateResult> WriteAsync(string address, byte value)
		{
			XGBFastEnet.<WriteAsync>d__47 <WriteAsync>d__ = new XGBFastEnet.<WriteAsync>d__47();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<XGBFastEnet.<WriteAsync>d__47>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.LSIS.XGBFastEnet.WriteCoil(System.String,System.Boolean)" />
		// Token: 0x06000A2F RID: 2607 RVA: 0x0003C1EC File Offset: 0x0003A3EC
		[DebuggerStepThrough]
		public Task<OperateResult> WriteCoilAsync(string address, bool value)
		{
			XGBFastEnet.<WriteCoilAsync>d__48 <WriteCoilAsync>d__ = new XGBFastEnet.<WriteCoilAsync>d__48();
			<WriteCoilAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteCoilAsync>d__.<>4__this = this;
			<WriteCoilAsync>d__.address = address;
			<WriteCoilAsync>d__.value = value;
			<WriteCoilAsync>d__.<>1__state = -1;
			<WriteCoilAsync>d__.<>t__builder.Start<XGBFastEnet.<WriteCoilAsync>d__48>(ref <WriteCoilAsync>d__);
			return <WriteCoilAsync>d__.<>t__builder.Task;
		}

		/// <inheritdoc cref="M:HslCommunication.Profinet.LSIS.XGBFastEnet.Write(System.String,System.Boolean)" />
		// Token: 0x06000A30 RID: 2608 RVA: 0x0003C240 File Offset: 0x0003A440
		[DebuggerStepThrough]
		public override Task<OperateResult> WriteAsync(string address, bool value)
		{
			XGBFastEnet.<WriteAsync>d__49 <WriteAsync>d__ = new XGBFastEnet.<WriteAsync>d__49();
			<WriteAsync>d__.<>t__builder = AsyncTaskMethodBuilder<OperateResult>.Create();
			<WriteAsync>d__.<>4__this = this;
			<WriteAsync>d__.address = address;
			<WriteAsync>d__.value = value;
			<WriteAsync>d__.<>1__state = -1;
			<WriteAsync>d__.<>t__builder.Start<XGBFastEnet.<WriteAsync>d__49>(ref <WriteAsync>d__);
			return <WriteAsync>d__.<>t__builder.Task;
		}

		// Token: 0x06000A31 RID: 2609 RVA: 0x0003C294 File Offset: 0x0003A494
		private byte[] PackCommand(byte[] coreCommand)
		{
			byte[] array = new byte[coreCommand.Length + 20];
			Encoding.ASCII.GetBytes(this.CompanyID).CopyTo(array, 0);
			switch (this.cpuInfo)
			{
			case LSCpuInfo.XGK:
				array[12] = 160;
				break;
			case LSCpuInfo.XGI:
				array[12] = 164;
				break;
			case LSCpuInfo.XGR:
				array[12] = 168;
				break;
			case LSCpuInfo.XGB_MK:
				array[12] = 176;
				break;
			case LSCpuInfo.XGB_IEC:
				array[12] = 180;
				break;
			}
			array[13] = 51;
			BitConverter.GetBytes((short)coreCommand.Length).CopyTo(array, 16);
			array[18] = this.baseNo * 16 + this.slotNo;
			int num = 0;
			for (int i = 0; i < 19; i++)
			{
				num += (int)array[i];
			}
			array[19] = (byte)num;
			coreCommand.CopyTo(array, 20);
			string text = SoftBasic.ByteToHexString(array, ' ');
			return array;
		}

		/// <inheritdoc />
		// Token: 0x06000A32 RID: 2610 RVA: 0x0003C397 File Offset: 0x0003A597
		public override string ToString()
		{
			return string.Format("XGBFastEnet[{0}:{1}]", this.IpAddress, this.Port);
		}

		/// <summary>
		/// 需要传入 MX100.2 的 100.2 部分，返回的是
		/// AnalysisAddress IX0.0.0 QX0.0.0  MW1.0  MB1.0
		/// </summary>
		/// <param name="address">start address</param>
		/// <param name="QI">is Q or I data</param>
		/// <returns>int address</returns>
		// Token: 0x06000A33 RID: 2611 RVA: 0x0003C3B4 File Offset: 0x0003A5B4
		public static int CalculateAddressStarted(string address, bool QI = false)
		{
			bool flag = address.IndexOf('.') < 0;
			int result;
			if (flag)
			{
				result = Convert.ToInt32(address);
			}
			else
			{
				string[] array = address.Split(new char[]
				{
					'.'
				});
				bool flag2 = !QI;
				if (flag2)
				{
					result = Convert.ToInt32(array[0]);
				}
				else
				{
					bool flag3 = array.Length >= 4;
					if (flag3)
					{
						result = Convert.ToInt32(array[3]);
					}
					else
					{
						result = Convert.ToInt32(array[2]);
					}
				}
			}
			return result;
		}

		/// <summary>
		/// NumberStyles HexNumber
		/// </summary>
		/// <param name="value"></param>
		/// <returns></returns>
		// Token: 0x06000A34 RID: 2612 RVA: 0x0003C428 File Offset: 0x0003A628
		private static bool IsHex(string value)
		{
			bool flag = string.IsNullOrEmpty(value);
			bool result;
			if (flag)
			{
				result = false;
			}
			else
			{
				bool flag2 = false;
				int i = 0;
				while (i < value.Length)
				{
					char c = value[i];
					char c2 = c;
					switch (c2)
					{
					case 'A':
					case 'B':
					case 'C':
					case 'D':
					case 'E':
					case 'F':
						goto IL_6B;
					default:
						switch (c2)
						{
						case 'a':
						case 'b':
						case 'c':
						case 'd':
						case 'e':
						case 'f':
							goto IL_6B;
						}
						break;
					}
					IL_6F:
					i++;
					continue;
					IL_6B:
					flag2 = true;
					goto IL_6F;
				}
				result = flag2;
			}
			return result;
		}

		/// <summary>
		/// AnalysisAddress
		/// </summary>
		/// <param name="address">start address</param>
		/// <param name="IsReadWrite">is read or write operate</param>
		/// <returns>analysis result</returns>
		// Token: 0x06000A35 RID: 2613 RVA: 0x0003C4C0 File Offset: 0x0003A6C0
		public static OperateResult<string> AnalysisAddress(string address, bool IsReadWrite)
		{
			StringBuilder stringBuilder = new StringBuilder();
			try
			{
				stringBuilder.Append("%");
				bool flag = false;
				if (IsReadWrite)
				{
					for (int i = 0; i < XGBFastEnet.AddressTypes.Length; i++)
					{
						bool flag2 = XGBFastEnet.AddressTypes[i] == address[0];
						if (flag2)
						{
							stringBuilder.Append(XGBFastEnet.AddressTypes[i]);
							char c = address[1];
							char c2 = c;
							if (c2 != 'X')
							{
								stringBuilder.Append("B");
								bool flag3 = address[1] == 'B';
								if (flag3)
								{
									bool flag4 = address[0] == 'I' || address[0] == 'Q' || address[0] == 'U';
									int num;
									if (flag4)
									{
										num = XGBFastEnet.CalculateAddressStarted(address.Substring(2), true);
									}
									else
									{
										num = XGBFastEnet.CalculateAddressStarted(address.Substring(2), false);
									}
									stringBuilder.Append((num == 0) ? num : (num * 2));
								}
								else
								{
									bool flag5 = address[1] == 'W';
									if (flag5)
									{
										bool flag6 = address[0] == 'I' || address[0] == 'Q' || address[0] == 'U';
										int num;
										if (flag6)
										{
											num = XGBFastEnet.CalculateAddressStarted(address.Substring(2), true);
										}
										else
										{
											num = XGBFastEnet.CalculateAddressStarted(address.Substring(2), false);
										}
										stringBuilder.Append((num == 0) ? num : (num * 2));
									}
									else
									{
										bool flag7 = address[1] == 'D';
										if (flag7)
										{
											int num = XGBFastEnet.CalculateAddressStarted(address.Substring(2), false);
											stringBuilder.Append((num == 0) ? num : (num * 4));
										}
										else
										{
											bool flag8 = address[1] == 'L';
											if (flag8)
											{
												int num = XGBFastEnet.CalculateAddressStarted(address.Substring(2), false);
												stringBuilder.Append((num == 0) ? num : (num * 8));
											}
											else
											{
												bool flag9 = address[0] == 'I' || address[0] == 'Q' || address[0] == 'U';
												if (flag9)
												{
													stringBuilder.Append(XGBFastEnet.CalculateAddressStarted(address.Substring(1), true));
												}
												else
												{
													bool flag10 = XGBFastEnet.IsHex(address.Substring(1));
													if (flag10)
													{
														stringBuilder.Append(address.Substring(1));
													}
													else
													{
														stringBuilder.Append(XGBFastEnet.CalculateAddressStarted(address.Substring(1), false));
													}
												}
											}
										}
									}
								}
							}
							else
							{
								stringBuilder.Append("X");
								bool flag11 = address[0] == 'I' || address[0] == 'Q' || address[0] == 'U';
								if (flag11)
								{
									stringBuilder.Append(XGBFastEnet.CalculateAddressStarted(address.Substring(2), true));
								}
								else
								{
									bool flag12 = XGBFastEnet.IsHex(address.Substring(2));
									if (flag12)
									{
										stringBuilder.Append(address.Substring(2));
									}
									else
									{
										stringBuilder.Append(XGBFastEnet.CalculateAddressStarted(address.Substring(2), false));
									}
								}
							}
							flag = true;
							break;
						}
					}
				}
				else
				{
					stringBuilder.Append(address);
					flag = true;
				}
				bool flag13 = !flag;
				if (flag13)
				{
					throw new Exception(StringResources.Language.NotSupportedDataType);
				}
			}
			catch (Exception ex)
			{
				return new OperateResult<string>(ex.Message);
			}
			return OperateResult.CreateSuccessResult<string>(stringBuilder.ToString());
		}

		/// <summary>
		/// Get DataType to Address
		/// </summary>
		/// <param name="address">address</param>
		/// <returns>dataType</returns>
		// Token: 0x06000A36 RID: 2614 RVA: 0x0003C854 File Offset: 0x0003AA54
		public static OperateResult<string> GetDataTypeToAddress(string address)
		{
			string value = string.Empty;
			try
			{
				char[] array = new char[]
				{
					'P',
					'M',
					'L',
					'K',
					'F',
					'T',
					'C',
					'D',
					'S',
					'Q',
					'I',
					'R'
				};
				bool flag = false;
				for (int i = 0; i < array.Length; i++)
				{
					bool flag2 = array[i] == address[0];
					if (flag2)
					{
						char c = address[1];
						char c2 = c;
						if (c2 <= 'D')
						{
							if (c2 == 'B')
							{
								value = "Continuous";
								goto IL_A4;
							}
							if (c2 == 'D')
							{
								value = "DWord";
								goto IL_A4;
							}
						}
						else
						{
							if (c2 == 'L')
							{
								value = "LWord";
								goto IL_A4;
							}
							if (c2 == 'W')
							{
								value = "Word";
								goto IL_A4;
							}
							if (c2 == 'X')
							{
								value = "Bit";
								goto IL_A4;
							}
						}
						value = "Continuous";
						IL_A4:
						flag = true;
						break;
					}
				}
				bool flag3 = !flag;
				if (flag3)
				{
					throw new Exception(StringResources.Language.NotSupportedDataType);
				}
			}
			catch (Exception ex)
			{
				return new OperateResult<string>(ex.Message);
			}
			return OperateResult.CreateSuccessResult<string>(value);
		}

		// Token: 0x06000A37 RID: 2615 RVA: 0x0003C96C File Offset: 0x0003AB6C
		private static OperateResult<byte[]> BuildReadByteCommand(string address, ushort length)
		{
			OperateResult<string> operateResult = XGBFastEnet.AnalysisAddress(address, true);
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				OperateResult<string> dataTypeToAddress = XGBFastEnet.GetDataTypeToAddress(address);
				bool flag2 = !dataTypeToAddress.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<byte[]>(dataTypeToAddress);
				}
				else
				{
					byte[] array = new byte[12 + operateResult.Content.Length];
					string content = dataTypeToAddress.Content;
					string a = content;
					if (!(a == "Bit"))
					{
						if (a == "Word" || a == "DWord" || a == "LWord" || a == "Continuous")
						{
							array[2] = 20;
						}
					}
					else
					{
						array[2] = 0;
					}
					array[0] = 84;
					array[1] = 0;
					array[3] = 0;
					array[4] = 0;
					array[5] = 0;
					array[6] = 1;
					array[7] = 0;
					array[8] = (byte)operateResult.Content.Length;
					array[9] = 0;
					Encoding.ASCII.GetBytes(operateResult.Content).CopyTo(array, 10);
					BitConverter.GetBytes(length).CopyTo(array, array.Length - 2);
					result = OperateResult.CreateSuccessResult<byte[]>(array);
				}
			}
			return result;
		}

		// Token: 0x06000A38 RID: 2616 RVA: 0x0003CAA0 File Offset: 0x0003ACA0
		private OperateResult<byte[]> BuildWriteByteCommand(string address, byte[] data)
		{
			string setCpuType = this.SetCpuType;
			string a = setCpuType;
			OperateResult<string> operateResult;
			if (!(a == "XGK"))
			{
				if (!(a == "XGB"))
				{
					operateResult = XGBFastEnet.AnalysisAddress(address, true);
				}
				else
				{
					operateResult = XGBFastEnet.AnalysisAddress(address, false);
				}
			}
			else
			{
				operateResult = XGBFastEnet.AnalysisAddress(address, true);
			}
			bool flag = !operateResult.IsSuccess;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = OperateResult.CreateFailedResult<byte[]>(operateResult);
			}
			else
			{
				OperateResult<string> dataTypeToAddress = XGBFastEnet.GetDataTypeToAddress(address);
				bool flag2 = !dataTypeToAddress.IsSuccess;
				if (flag2)
				{
					result = OperateResult.CreateFailedResult<byte[]>(dataTypeToAddress);
				}
				else
				{
					byte[] array = new byte[12 + operateResult.Content.Length + data.Length];
					string content = dataTypeToAddress.Content;
					string a2 = content;
					if (!(a2 == "Bit") && !(a2 == "Byte"))
					{
						if (!(a2 == "Word"))
						{
							if (!(a2 == "DWord"))
							{
								if (!(a2 == "LWord"))
								{
									if (a2 == "Continuous")
									{
										array[2] = 20;
									}
								}
								else
								{
									array[2] = 4;
								}
							}
							else
							{
								array[2] = 3;
							}
						}
						else
						{
							array[2] = 2;
						}
					}
					else
					{
						array[2] = 1;
					}
					array[0] = 88;
					array[1] = 0;
					array[3] = 0;
					array[4] = 0;
					array[5] = 0;
					array[6] = 1;
					array[7] = 0;
					array[8] = (byte)operateResult.Content.Length;
					array[9] = 0;
					Encoding.ASCII.GetBytes(operateResult.Content).CopyTo(array, 10);
					BitConverter.GetBytes(data.Length).CopyTo(array, array.Length - 2 - data.Length);
					data.CopyTo(array, array.Length - data.Length);
					result = OperateResult.CreateSuccessResult<byte[]>(array);
				}
			}
			return result;
		}

		/// <summary>
		/// Returns true data content, supports read and write returns
		/// </summary>
		/// <param name="response">response data</param>
		/// <returns>real data</returns>
		// Token: 0x06000A39 RID: 2617 RVA: 0x0003CC4C File Offset: 0x0003AE4C
		public OperateResult<byte[]> ExtractActualData(byte[] response)
		{
			bool flag = response.Length < 20;
			OperateResult<byte[]> result;
			if (flag)
			{
				result = new OperateResult<byte[]>("Length is less than 20:" + SoftBasic.ByteToHexString(response));
			}
			else
			{
				ushort num = BitConverter.ToUInt16(response, 10);
				BitArray bitArray = new BitArray(BitConverter.GetBytes(num));
				int num2 = (int)(num % 32);
				switch (num % 32)
				{
				case 1:
					this.CpuType = "XGK/R-CPUH";
					break;
				case 2:
					this.CpuType = "XGK-CPUS";
					break;
				case 4:
					this.CpuType = "XGK-CPUE";
					break;
				case 5:
					this.CpuType = "XGK/R-CPUH";
					break;
				case 6:
					this.CpuType = "XGB/XBCU";
					break;
				}
				this.CpuError = bitArray[7];
				bool flag2 = bitArray[8];
				if (flag2)
				{
					this.LSCpuStatus = LSCpuStatus.RUN;
				}
				bool flag3 = bitArray[9];
				if (flag3)
				{
					this.LSCpuStatus = LSCpuStatus.STOP;
				}
				bool flag4 = bitArray[10];
				if (flag4)
				{
					this.LSCpuStatus = LSCpuStatus.ERROR;
				}
				bool flag5 = bitArray[11];
				if (flag5)
				{
					this.LSCpuStatus = LSCpuStatus.DEBUG;
				}
				bool flag6 = response.Length < 28;
				if (flag6)
				{
					result = new OperateResult<byte[]>("Length is less than 28:" + SoftBasic.ByteToHexString(response));
				}
				else
				{
					ushort num3 = BitConverter.ToUInt16(response, 26);
					bool flag7 = num3 > 0;
					if (flag7)
					{
						result = new OperateResult<byte[]>((int)response[28], "Error:" + XGBFastEnet.GetErrorDesciption(response[28]));
					}
					else
					{
						bool flag8 = response[20] == 89;
						if (flag8)
						{
							result = OperateResult.CreateSuccessResult<byte[]>(new byte[0]);
						}
						else
						{
							bool flag9 = response[20] == 85;
							if (flag9)
							{
								try
								{
									ushort num4 = BitConverter.ToUInt16(response, 30);
									byte[] array = new byte[(int)num4];
									Array.Copy(response, 32, array, 0, (int)num4);
									return OperateResult.CreateSuccessResult<byte[]>(array);
								}
								catch (Exception ex)
								{
									return new OperateResult<byte[]>(ex.Message);
								}
							}
							result = new OperateResult<byte[]>(StringResources.Language.NotSupportedFunction);
						}
					}
				}
			}
			return result;
		}

		/// <summary>
		/// get the description of the error code meanning
		/// </summary>
		/// <param name="code">code value</param>
		/// <returns>string information</returns>
		// Token: 0x06000A3A RID: 2618 RVA: 0x0003CE64 File Offset: 0x0003B064
		public static string GetErrorDesciption(byte code)
		{
			if (code <= 34)
			{
				switch (code)
				{
				case 0:
					return "Normal";
				case 1:
					return "Physical layer error (TX, RX unavailable)";
				case 2:
					break;
				case 3:
					return "There is no identifier of Function Block to receive in communication channel";
				case 4:
					return "Mismatch of data type";
				case 5:
					return "Reset is received from partner station";
				case 6:
					return "Communication instruction of partner station is not ready status";
				case 7:
					return "Device status of remote station is not desirable status";
				case 8:
					return "Access to some target is not available";
				case 9:
					return "Can’ t deal with communication instruction of partner station by too many reception";
				case 10:
					return "Time Out error";
				case 11:
					return "Structure error";
				case 12:
					return "Abort";
				case 13:
					return "Reject(local/remote)";
				case 14:
					return "Communication channel establishment error (Connect/Disconnect)";
				case 15:
					return "High speed communication and connection service error";
				default:
					if (code == 33)
					{
						return "Can’t find variable identifier";
					}
					if (code == 34)
					{
						return "Address error";
					}
					break;
				}
			}
			else
			{
				if (code == 50)
				{
					return "Response error";
				}
				if (code == 113)
				{
					return "Object Access Unsupported";
				}
				if (code == 187)
				{
					return "Unknown error code (communication code of other company) is received";
				}
			}
			return "Unknown error";
		}

		// Token: 0x040002F3 RID: 755
		private string CompanyID1 = "LSIS-XGT";

		// Token: 0x040002F4 RID: 756
		private LSCpuInfo cpuInfo = LSCpuInfo.XGK;

		// Token: 0x040002F5 RID: 757
		private byte baseNo = 0;

		// Token: 0x040002F6 RID: 758
		private byte slotNo = 3;

		/// <summary>
		/// 所有支持的地址信息
		/// </summary>
		// Token: 0x040002F7 RID: 759
		public static string AddressTypes = "PMLKFTCDSQINUZR";
	}
}
